package com.wencst.security.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

import com.wencst.security.bean.User;

import lombok.extern.slf4j.Slf4j;

/**
 * spring security 验证登录用户名密码类
 * @author wencst
 *
 */
@Slf4j
@Component
public class MyUserDetailsService implements UserDetailsService {

	@Autowired
	PasswordEncoder passwordEncoder;
	@Autowired
	UserService userService;
	
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		User user = userService.getUserByName(username);
		log.info("-----login user "+username+" get detail = "+user.toString());
		return user;
	}

}
